﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>判断控件的类型</title>
    <script type="text/javascript" language="JavaScript">
        function test(frmObj){
            // 考虑到input有多种类型，所以还需要判断type属性
            if(frmObj.tagName === "INPUT")
                alert("您操作的控件类型是："+ frmObj.type) ;
            else
                alert("您操作的控件类型是："+ frmObj.tagName);
        }
    </script>
</head>
<body>
<input type=text name="txt1" value="this is test!" onchange="test(this)">
<input type=button value="判断" onClick="test(this)">
</body>
</html>